#pragma once

class ComputerExamineUI : public CContainerUI
{
public:
	ComputerExamineUI()
	{
		CDialogBuilder builder;
		CContainerUI* pComputerExamine = static_cast<CContainerUI*>(builder.Create(_T("ComputerExamine.xml"), (UINT)0));
		if( pComputerExamine ) {
			this->Add(pComputerExamine);
		}
		else {
			this->RemoveAll();
			return;
		}
	}
};

class CRealWndUI : public CControlUI, public IPreMessageFilterUI
{
public:
	CRealWndUI() : m_hRealWnd(NULL)
	{
	}

    virtual ~CRealWndUI()
	{
		m_pManager->RemovePreMessageFilter(this);
	}

	virtual void DoInit()
	{
		CControlUI::DoInit();
		m_pManager->AddPreMessageFilter(this);
	}

	void SetWnd(HWND hWnd) { m_hRealWnd = hWnd; }

	virtual LPCTSTR GetClass() const
	{
		return _T("RealWndUI");
	}

	virtual LPVOID GetInterface(LPCTSTR pstrName)
	{
		if( _tcscmp(pstrName, _T("RealWnd")) == 0 ) return static_cast<CRealWndUI*>(this);
		return CControlUI::GetInterface(pstrName);
	}

	virtual void SetVisible(bool bVisible = true)
	{
		CControlUI::SetVisible(bVisible);
		::ShowWindow(m_hRealWnd, IsVisible() ? SW_SHOW : SW_HIDE);
	}

    virtual void SetInternVisible(bool bVisible = true)
	{
		CControlUI::SetInternVisible(bVisible);
        ::ShowWindow(m_hRealWnd, IsVisible() ? SW_SHOW : SW_HIDE);
	}

    virtual void SetPos(RECT rc)
	{
		CControlUI::SetPos(rc);

		::MoveWindow(m_hRealWnd, m_rcItem.left, m_rcItem.top, m_rcItem.right - m_rcItem.left, m_rcItem.bottom - m_rcItem.top, TRUE);
	}

    virtual void DoPaint(HDC hDC, const RECT& rcPaint)
	{
	}

    virtual void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
	{
		CControlUI::SetAttribute(pstrName, pstrValue);
	}

	LRESULT PreMessageHandler(const LPMSG pMsg, bool& bHandled)
	{
		bHandled = false;

		if(pMsg->hwnd == m_hRealWnd)
		{
			switch(pMsg->message)
			{
			case WM_SETFOCUS:
				this->SetFocus();
				break;
			}
		}

		return 0;
	}

protected:
	HWND m_hRealWnd;
};

class CDialogBuilderCallbackEx : public IDialogBuilderCallback
{
public:
	CControlUI* CreateControl(LPCTSTR pstrClass) 
	{
		if( _tcscmp(pstrClass, _T("ComputerExamine")) == 0 ) return new ComputerExamineUI;
		if( _tcscmp(pstrClass, _T("RealWnd")) == 0 ) return new CRealWndUI;
		return NULL;
	}
};